package client_gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

import utils.Constants;
import utils.ImageCreator;
import actions.AddUserAction;
import actions.FindAction;

/**
 * Klasa predstavlja dialog za pretragu korisnika.
 * Klikom na dugme Find, serveru se salju parametri za pretragu korisnika.
 * 
 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
 */
public class FindUserDialog extends JDialog implements Constants {

	/**
	 * Parent - prozor aplikacije.
	 */
	private ClientWindow owner;
	
	/**
	 * Vector sa kompletnim podacima - svim kolonama.
	 */
	private Vector<Vector<Object>> completeData = new Vector<Vector<Object>>();
	
	/**
	 * Vector sa kolonama koje se prikazuju u tabeli.
	 */
	private Vector<Vector<Object>> tableData = new Vector<Vector<Object>>();
	
	
	/**
	 * Podatak koji odgovara selektovanom radio button-u.
	 */
	private String selectedRadio = "username";
	
	
	private JPanel jContentPane = null;
	
	
	/**
	 * Panel za pretragu.
	 */
	private JPanel findPanel = null;
	
	
	/**
	 * Panel za kriterijume pretrazivanja.
	 */
	private JPanel criteriumPanel = null;
	
	
	/**
	 * Panel sa tabelom.
	 */
	private JPanel tablePanel = null;
	
	
	/**
	 * Panel sa dugmadima.
	 */
	private JPanel buttonPanel = null;
	

	private GridBagLayout findGridBag = null;
	private GridBagLayout criteriumGridBag = null;
	private FlowLayout buttonFlow = null;
	private BorderLayout listingBorder = null;
	
	
	private FindAction findButton = null;
	private AddUserAction addButton = null;
	private JButton closeButton = null;
	
	private JLabel findLabel = null;
	private JTextField findField = null;
	private JLabel allUserText = null;
	
	private JRadioButton usernameRadioButton = null;
	private JRadioButton nicknameRadioButton = null;
	private JRadioButton emailRadioButton = null;
	private JCheckBox offlineCheckBox = null;
	
	private JScrollPane tableScrollPane = null;
	private JTable table = null;
	
	
	private ButtonGroup radioGroup = null;

	
	private GridBagConstraints findLabelConstraint = null;
	private GridBagConstraints findFieldConstraint = null;
	private GridBagConstraints allUserTextConstraint = null;
	private GridBagConstraints usernameRadioConstraint = null;
	private GridBagConstraints nicknameRadioConstraint = null;
	private GridBagConstraints emailRadioConstraint = null;
	private GridBagConstraints offlineCheckConstraint = null;
	
	
	/**
	 * Predstavlja selektovani red tabele.
	 */
	private int selectedRow = -1;
	
	
	
	/**
	 * Konstruktor.
	 * @param parent - prozor aplikacije
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	public FindUserDialog(ClientWindow parent) {
		super(parent, "Find User", true);
		
		this.owner = parent;
		
		radioGroup = new ButtonGroup();
		
		initializeLayoutManagers();
		
		createConstraints();
		
		initializeConstraints();
		
		initialize();
	}
	
	
	
	/**
	 * Metod vrsi inicijalizaciju dialoga.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private void initialize() {
		this.setSize(500, 400);
		this.setLocation(owner.getX() + owner.getWidth() / 2 - this.getWidth() / 2, owner.getY() + owner.getHeight() / 2 - this.getHeight() / 2);
		this.setResizable(false);
		this.setContentPane(getJContentPane());
		
		this.setIconImage(owner.getIconImage());
	}
	
	
	private void initializeLayoutManagers() {
		findGridBag = new GridBagLayout();
		criteriumGridBag = new GridBagLayout();
		buttonFlow = new FlowLayout(FlowLayout.CENTER);
		listingBorder = new BorderLayout();
		
		buttonFlow.setHgap(30);
	}
	
	
	private void createConstraints() {
		findLabelConstraint = new GridBagConstraints();
		findFieldConstraint = new GridBagConstraints();
		allUserTextConstraint = new GridBagConstraints();
		usernameRadioConstraint = new GridBagConstraints();
		nicknameRadioConstraint = new GridBagConstraints();
		emailRadioConstraint = new GridBagConstraints();
		offlineCheckConstraint = new GridBagConstraints();
	}
	
	
	private void initializeConstraints() {
		findLabelConstraint.gridx = 0;
		findLabelConstraint.gridy = 0;
		findLabelConstraint.weightx = 1;
		findLabelConstraint.weighty = 1;
		findLabelConstraint.anchor = GridBagConstraints.NORTHWEST;
		findLabelConstraint.insets = new Insets(0,10,5,0);
		
		findFieldConstraint.gridx = 1;
		findFieldConstraint.gridy = 0;
		findFieldConstraint.weightx = 1;
		findFieldConstraint.weighty = 1;
		findFieldConstraint.anchor = GridBagConstraints.NORTHWEST;
		findFieldConstraint.insets = new Insets(0,5,5,0);
		
		allUserTextConstraint.gridx = 1;
		allUserTextConstraint.gridy = 1;
		allUserTextConstraint.weightx = 1;
		allUserTextConstraint.weighty = 1;
		allUserTextConstraint.anchor = GridBagConstraints.NORTHWEST;
		allUserTextConstraint.insets = new Insets(0,5,5,0);
		
		usernameRadioConstraint.gridx = 0;
		usernameRadioConstraint.gridy = 1;
		usernameRadioConstraint.weightx = 1;
		usernameRadioConstraint.weighty = 1;
		usernameRadioConstraint.anchor = GridBagConstraints.NORTHWEST;
		usernameRadioConstraint.insets = new Insets(0,5,5,0);
		
		nicknameRadioConstraint.gridx = 0;
		nicknameRadioConstraint.gridy = 2;
		nicknameRadioConstraint.weightx = 1;
		nicknameRadioConstraint.weighty = 1;
		nicknameRadioConstraint.anchor = GridBagConstraints.NORTHWEST;
		nicknameRadioConstraint.insets = new Insets(0,5,5,0);
		
		emailRadioConstraint.gridx = 0;
		emailRadioConstraint.gridy = 3;
		emailRadioConstraint.weightx = 1;
		emailRadioConstraint.weighty = 1;
		emailRadioConstraint.anchor = GridBagConstraints.NORTHWEST;
		emailRadioConstraint.insets = new Insets(0,5,5,0);
		
		offlineCheckConstraint.gridx = 0;
		offlineCheckConstraint.gridy = 5;
		offlineCheckConstraint.weightx = 1;
		offlineCheckConstraint.weighty = 1;
		offlineCheckConstraint.anchor = GridBagConstraints.NORTHWEST;
		offlineCheckConstraint.insets = new Insets(0,5,5,0);
	}

	
	
	
	// Metode koje inicijalizuju komponente dialoga.
	
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			
			jContentPane.setLayout(null);
			
			jContentPane.add(getFindPanel());
			jContentPane.add(getCriteriumPanel());
			jContentPane.add(getButtonPanel());
			jContentPane.add(getTablePanel());

		}
		
		return jContentPane;
	}
	
	
	private JPanel getFindPanel() {
		if (findPanel == null) {
			findPanel = new JPanel();
			findPanel.setLocation(5, 0);
			findPanel.setSize(300,80);
			findPanel.setLayout(findGridBag);

			TitledBorder titledBorder = BorderFactory.createTitledBorder(BorderFactory.
					createEtchedBorder(EtchedBorder.RAISED),
					"Find", javax.swing.border.TitledBorder.CENTER,
					javax.swing.border.TitledBorder.DEFAULT_POSITION,
					null, null);
			
			findPanel.setBorder(titledBorder);
			
			findPanel.add(getFindLabel(), findLabelConstraint);
			findPanel.add(getFindField(), findFieldConstraint);
			findPanel.add(getAllUserText(), allUserTextConstraint);
		}
		
		return findPanel;
	}
	
	
	
	private JPanel getCriteriumPanel() {
		if (criteriumPanel == null) {
			criteriumPanel = new JPanel();
			criteriumPanel.setLocation(320, 0);
			criteriumPanel.setSize(165,160);
			criteriumPanel.setLayout(criteriumGridBag);
			
			TitledBorder titledBorder = BorderFactory.createTitledBorder(BorderFactory.
					createEtchedBorder(EtchedBorder.RAISED),
					"Criterium", javax.swing.border.TitledBorder.CENTER,
					javax.swing.border.TitledBorder.DEFAULT_POSITION,
					null, null);
			
			criteriumPanel.setBorder(titledBorder);
			
			criteriumPanel.add(getUsernameRadioButton(), usernameRadioConstraint);
			criteriumPanel.add(getNicknameRadioButton(), nicknameRadioConstraint);
			criteriumPanel.add(getEmailRadioButton(), emailRadioConstraint);
			criteriumPanel.add(getOfflineCheckBox(), offlineCheckConstraint);
		}
		
		return criteriumPanel;
	}
	
	
	private JPanel getButtonPanel() {
		if (buttonPanel == null) {
			buttonPanel = new JPanel();
			buttonPanel.setLocation(5, 90);
			buttonPanel.setSize(300,70);
			buttonPanel.setLayout(buttonFlow);
			
			TitledBorder titledBorder = BorderFactory.createTitledBorder(BorderFactory.
					createEtchedBorder(EtchedBorder.RAISED),
					"Actions", javax.swing.border.TitledBorder.CENTER,
					javax.swing.border.TitledBorder.DEFAULT_POSITION,
					null, null);
			
			buttonPanel.setBorder(titledBorder);
			
			buttonPanel.add(getFindButton());
			buttonPanel.add(getAddButton());
			buttonPanel.add(getCloseButton());
		}
		
		return buttonPanel;
	}
	
	
	
	private JPanel getTablePanel() {
		if (tablePanel == null) {
			tablePanel = new JPanel();
			tablePanel.setLocation(5, 170);
			tablePanel.setSize(480,195);
			tablePanel.setLayout(listingBorder);
			
			TitledBorder titledBorder = BorderFactory.createTitledBorder(BorderFactory.
					createEtchedBorder(EtchedBorder.RAISED),
					"Search Listing", javax.swing.border.TitledBorder.CENTER,
					javax.swing.border.TitledBorder.DEFAULT_POSITION,
					null, null);
			
			tablePanel.setBorder(titledBorder);
			
			tablePanel.add(getTableScrollPanel(), BorderLayout.CENTER);
		}
		
		return tablePanel;
	}

	
	private FindAction getFindButton() {
		if (findButton == null) {
			findButton = new FindAction(owner, FindUserDialog.this);
			findButton.setPreferredSize(new Dimension(50, 30));
			findButton.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/actions/images/search.png"));
		}
		
		return findButton;
	}
	
	private AddUserAction getAddButton() {
		if (addButton == null) {
			addButton = new AddUserAction(owner, FindUserDialog.this);
			addButton.setPreferredSize(new Dimension(50, 30));
			addButton.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/actions/images/add.png"));
		}
		
		return addButton;
	}
	
	private JButton getCloseButton() {
		if (closeButton == null) {
			closeButton = new JButton();
			closeButton.setToolTipText("Close");
			closeButton.setPreferredSize(new Dimension(50, 30));
			closeButton.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/actions/images/close.png"));
			closeButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					FindUserDialog.this.dispose();
				}
			});
		}
		
		return closeButton;
	}
	
	
	private JLabel getFindLabel() {
		if (findLabel == null) {
			findLabel = new JLabel("Find:");
		}
		
		return findLabel;
	}
	
	private JTextField getFindField() {
		if (findField == null) {
			findField = new JTextField();
			findField.setPreferredSize(new Dimension(200, 20));
			findField.addKeyListener(new KeyAdapter() {
				public void keyPressed(KeyEvent e) {
					if (e.getKeyCode() == KeyEvent.VK_ENTER) {
						findButton.doClick();
					} else
					if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
						closeButton.doClick();
					}
				}
			});
		}
		
		return findField;
	}
	
	private JLabel getAllUserText() {
		if (allUserText == null) {
			allUserText = new JLabel("* for all users");
		}
		
		return allUserText;
	}
	
	private JRadioButton getUsernameRadioButton() {
		if (usernameRadioButton == null) {
			usernameRadioButton = new JRadioButton("Username");
			radioGroup.add(usernameRadioButton);
			usernameRadioButton.setSelected(true);
			usernameRadioButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					selectedRadio = "username";
				}
			});
		}
		
		return usernameRadioButton;
	}
	
	private JRadioButton getNicknameRadioButton() {
		if (nicknameRadioButton == null) {
			nicknameRadioButton = new JRadioButton("Nickname");
			radioGroup.add(nicknameRadioButton);
			nicknameRadioButton.setSelected(false);
			nicknameRadioButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					selectedRadio = "nickname";
				}
			});
		}
		
		return nicknameRadioButton;
	}
	
	private JRadioButton getEmailRadioButton() {
		if (emailRadioButton == null) {
			emailRadioButton = new JRadioButton("Email");
			radioGroup.add(emailRadioButton);
			emailRadioButton.setSelected(false);
			emailRadioButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					selectedRadio = "email";
				}
			});
		}
		
		return emailRadioButton;
	}
	
	private JCheckBox getOfflineCheckBox() {
		if (offlineCheckBox == null) {
			offlineCheckBox = new JCheckBox("Show Offline Users");
			offlineCheckBox.setSelected(false);
		}
		
		return offlineCheckBox;
	}
	
	
	private JScrollPane getTableScrollPanel() {
		if (tableScrollPane == null) {
			tableScrollPane = new JScrollPane();
			tableScrollPane.setViewportView(getListingTable());
		}
		
		return tableScrollPane;
	}
	
	
	private JTable getListingTable() {
		if (table == null) {
			table = new JTable();
			
			FindUserTableModel model = new FindUserTableModel();
			
			table.setModel(model);
			table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			table.getSelectionModel().addListSelectionListener(new SelectionListener());
			table.setOpaque(true);
			table.getTableHeader().setReorderingAllowed(false);
			
			table.setRowHeight(22);

//			table.getColumn("No.").setMinWidth(30);
//			table.getColumn("No.").setMaxWidth(30);
			table.getColumn("Status").setMinWidth(80);
			table.getColumn("Status").setMaxWidth(80);

			table.setDefaultRenderer(UsernameClass.class, new UsernameTableCellRenderer());
			table.setDefaultRenderer(StatusClass.class, new StatusClassTableCellRenderer());
			table.setDefaultRenderer(Integer.class, new ClassTableCellRenderer());
			table.setDefaultRenderer(Object.class, new ClassTableCellRenderer());
		}
		
		return table;
	}
	

	
	/**
	 * Klasa predstavlja cell renderer polja tabele koja prikazuju status korisnika.
	 * Prosiruje JButton klasu, kako bi mogla da se doda ikonica u polje tabele, tj.
	 * na dubme u polju tabele.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private class StatusClassTableCellRenderer extends JButton implements TableCellRenderer {

		private Font font = new Font(this.getFont().getName(), Font.PLAIN, this.getFont().getSize());
		
		public StatusClassTableCellRenderer() {
			this.setBackground(Color.WHITE);
			this.setHorizontalAlignment(SwingConstants.LEFT);
			this.setBorderPainted(false);
			this.setMargin(new Insets(0,5,0,5));
			this.setBorder(null);
			this.setFont(font);
		}
				
		
		public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

			StatusClass statusCell = (StatusClass)table.getValueAt(row, 2);
			
			if (statusCell.getStatusName().equals("Online")) {
				this.setText("Online");
				this.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/status_images/Online.png"));
			} else
			if (statusCell.getStatusName().equals("Offline")) {
				this.setText("Offline");
				this.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/status_images/Offline.png"));
			} else
			if (statusCell.getStatusName().equals("Away")) {
				this.setText("Away");
				this.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/status_images/Away.png"));
			} else
			if (statusCell.getStatusName().equals("Busy")) {
				this.setText("Busy");
				this.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/status_images/Busy.png"));
			} else
			if (statusCell.getStatusName().equals("Invisible")) {
				this.setText("Offline");
				this.setIcon(ImageCreator.createImageIcon(FindUserDialog.class, "/status_images/Offline.png"));
			}


			if (isSelected) {
				// default swing color
				this.setBackground(new Color(185, 207, 230));
			}
			else {
				this.setBackground(Color.WHITE);
			}

			return this;
		}
	}

	
	
	/**
	 * Klasa predstavlja cell renderer polja tabele koja prikazuju username.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private class UsernameTableCellRenderer extends DefaultTableCellRenderer {
		
		private Font font = new Font(this.getFont().getName(), Font.BOLD, this.getFont().getSize());
		
		public UsernameTableCellRenderer() {
			this.setFont(font);
		}

		public Component getTableCellRendererComponent
			(JTable table, Object value, boolean selected, boolean focused, int row, int column) {

			UsernameClass statusCell = (UsernameClass)table.getValueAt(row, 0);
			
			this.setText(statusCell.getUsername());
			
			this.setHorizontalAlignment(SwingConstants.CENTER);
			
			if (selected) {
				// default swing color
				this.setBackground(new Color(185, 207, 230));
			}
			else {
				this.setBackground(Color.WHITE);
			}

			return this;
		}
	}
	
	
	
	
	/**
	 * Klasa predstavlja default cell renderer polja tabele. Koristi se kod svih polja, osim
	 * kod polja koje prikazuje status korisnika.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private class ClassTableCellRenderer extends DefaultTableCellRenderer {

		public Component getTableCellRendererComponent
			(JTable table, Object value, boolean selected, boolean focused, int row, int column) {

			setEnabled(table == null || table.isEnabled());

			setHorizontalAlignment(SwingConstants.CENTER);
			
			super.getTableCellRendererComponent(table, value, selected, focused, row, column);

			return this;
		}
	}
	
	
	
	/**
	 * Klasa predstavlja osluskivac dogadjaja selekcije reda u tabeli.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private class SelectionListener implements ListSelectionListener {
		public void valueChanged(ListSelectionEvent e) {

			selectedRow = table.getSelectedRow();
		}
	}
	
	
	/**
	 * Klasa predstavlja model tabele.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private class FindUserTableModel extends AbstractTableModel {
		
		private Vector<String> columnNames = new Vector<String>();
		
		public FindUserTableModel() {
//			columnNames.add("No.");
			columnNames.add("Username");
			columnNames.add("Nickname");
			columnNames.add("Status");
			columnNames.add("Email");
		}
		
		
		public int getColumnCount() {
			return columnNames.size();
		}
		
		public int getRowCount() {
			return tableData == null ? 0 : tableData.size();
		}

		public Object getValueAt(int rowIndex, int columnIndex) {
			return tableData.get(rowIndex).get(columnIndex);
		}
		

		@Override
		public Class<?> getColumnClass(int columnIndex) {
			if ( getValueAt(0, columnIndex) != null ) {
				return getValueAt(0, columnIndex).getClass();
			}
			return this.toString().getClass();
		}
		
		@Override
		public String getColumnName(int column) {
			return columnNames.get(column);
		}
		
		@Override
		public boolean isCellEditable(int rowIndex, int columnIndex) {
			return false;
		}
	}
	
	
	/**
	 * Klasa koja predstavlja klasu podataka koji renderuju Username kolonu.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private class UsernameClass {
		private String username;
		
		public UsernameClass(String username) {
			this.username = username;
		}
		
		public String getUsername() {
			return this.username;
		}
	}
	
	
	
	/**
	 * Klasa koja predstavlja klasu podataka koji renderuju Status kolonu.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	private class StatusClass {
		private String status;
		
		public StatusClass(String status) {
			this.status = status;
		}
		
		public String getStatusName() {
			return this.status;
		}
	}
	
	
	/**
	 * Metod vraca parametar iz Find polja.
	 * @return - parametar iz Find polja
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	public String getFindParameter() {
		return findField.getText();
	}
	
	
	/**
	 * Metod vraca parametar radio dugmeta.
	 * @return - parametar radio dugmeta
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	public String getRadioParameter() {
		return selectedRadio;
	}
	
	
	/**
	 * Metod vraca parametar check box-a.
	 * @return - parametar check box-a
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	public String getCheckParameter() {
		return offlineCheckBox.isSelected() == true ? "true" : "false";
	}
	
	
	/**
	 * Metod setuje model podataka tabele sa pronadjenim korisnicima.
	 * @param data - ulazni podaci
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	@SuppressWarnings("unchecked")
	public void setTableModel(Vector<Vector> data) {
		
		for (int i = 0; i < data.size(); i++) {
			Vector row = new Vector<Object>();
			Vector completeRow = new Vector<Object>();
			
			for (int j = 0; j < data.get(i).size(); j++) {
				completeRow.add(data.get(i).get(j));
			}
			
//			row.add(new Integer(i+1));
			row.add(new UsernameClass(data.get(i).get(0).toString()));
			row.add(data.get(i).get(1));
			row.add(new StatusClass(data.get(i).get(6).toString()));
			row.add(data.get(i).get(2));

			this.completeData.add(completeRow);
			this.tableData.add(row);
		}
		
		SwingUtilities.updateComponentTreeUI(table);
	}
	
	
	/**
	 * Metod prazni model podataka tabele sa pronadjenim korisnicima.
	 * @author UrosKrkic & Radivoje Popovic & Martin Jondzic
	 */
	public void clearTableModel() {
		completeData.clear();
		tableData.clear();
	}
	
	
	/**
	 * Vraca vektor koji predstavlja selektovani red. 
	 * @return - selektovani red sa kompletnim podacima
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public Vector getSelectedRow() {
		if (completeData.size() > 0 && selectedRow >= 0)
			return completeData.get(selectedRow);
		else
			return null;
	}
	
	
	/**
	 * Uklanja selektovani red iz tabele (odnosno modela tabele).
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public void removeSelectedRow() {
		completeData.remove(selectedRow);
		tableData.remove(selectedRow);
		
		SwingUtilities.updateComponentTreeUI(table);
	}
	
}
